﻿using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;

namespace VH.SharePoint.Api
{
    public class MediaItemInforCreation: IMediaItemInfo
    {
        public string Name { get; set; }

        public string Description { get; set; }

        public string Url { get; set; }

        public byte[] Content { get; set; }

        public string MimeType { get; set; }

        public bool Overwrite { get; set; }

        internal String GetRelativeUrl(SPFolder folder)
        {
            if (string.IsNullOrEmpty(Url))
            {
                return folder.ServerRelativeUrl + "/" + Name;
            }
            var fileName = SPUtility.GetUrlFileName(Url);
            return folder.ServerRelativeUrl + "/" + Url.Replace(folder.ServerRelativeUrl, "").Replace("/" + fileName,"");
        }
    }
}